<?php

class eventActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
        $this->events = Doctrine_Core::getTable('Event')->findAll();
    }

    public function executeEdit(sfWebRequest $request) {
        $this->forward404Unless($event = Doctrine::getTable('Event')->find(array($request->getParameter('id'))), sprintf('Event does not exist (%s).', $request->getParameter('id')));
        $this->form = new EventForm($event);
    }

    public function executeSubmit(sfWebRequest $request) {
        $tainted_values = $request->getParameter('event');
        $event = Doctrine::getTable('Event')->find($tainted_values['id']);

        $this->form = new EventForm($event);

        if ($request->isMethod('post') && $this->form->bindAndSave($tainted_values))
            $this->redirect('@homepage');

        $this->setTemplate('edit');
    }

    public function executeAdd(sfWebRequest $request) {
        $this->forward404unless($request->isXmlHttpRequest());
        $number = intval($request->getParameter("num"));

        $this->form = new EventForm();

        $this->form->addNewFields($number);

        return $this->renderPartial('addNew', array('form' => $this->form, 'number' => $number));
    }

   

    public function executeNew(sfWebRequest $request) {
        $event = new Event();
        $this->form = new EventForm($event);

        $this->form->addNewFields(0);

        $this->setTemplate('edit');
    }

}